//
//  AppDelegate.m
//  ZDPension
//
//  Created by 刘甲奇 on 2017/6/13.
//  Copyright © 2017年 maker. All rights reserved.
//

#import "AppDelegate.h"
#import <MMDrawerController/MMDrawerController.h>
#import "ZDLeftDrawerController.h"
#import "ZDMainController.h"
#import "ZDNavigationController.h"

#import <AMapFoundationKit/AMapServices.h>
#import <AMapLocationKit/AMapLocationKit.h>

@interface AppDelegate ()
/**
 <#Description#>
 */
@property(nonatomic, strong) AMapLocationManager *locationManager;

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] init];
    self.window.bounds = [UIScreen mainScreen].bounds;
    [self.window makeKeyAndVisible];
    
    //配置第三方的信息
    [self configureService:launchOptions];

    [self setRootController];
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{

}

- (void)applicationDidEnterBackground:(UIApplication *)application
{

}

- (void)applicationWillEnterForeground:(UIApplication *)application
{

}

- (void)applicationDidBecomeActive:(UIApplication *)application
{

}

- (void)applicationWillTerminate:(UIApplication *)application
{

}
#pragma mark- privateMethod

/**
 设置跟控制器器
 */
- (void)setRootController
{
    ZDLeftDrawerController * leftDrawer = [[ZDLeftDrawerController alloc] init];
    ZDNavigationController *leftNav = [[ZDNavigationController alloc] initWithRootViewController:leftDrawer];
    ZDMainController * main = [[ZDMainController alloc] init];
    ZDNavigationController *nav = [[ZDNavigationController alloc] initWithRootViewController:main];
    
    MMDrawerController *drawerController = [[MMDrawerController alloc] initWithCenterViewController:nav leftDrawerViewController:leftNav];
    drawerController.openDrawerGestureModeMask = MMOpenDrawerGestureModeAll;
    drawerController.closeDrawerGestureModeMask =MMCloseDrawerGestureModeAll;
    drawerController.maximumLeftDrawerWidth = 250.0;
    
    self.window.rootViewController = drawerController;
}

/**
 配置第三方

 @param launchOptions <#launchOptions description#>
 */
- (void)configureService:(NSDictionary *)launchOptions
{
    [AMapServices sharedServices].apiKey = GAODE_APPKEY;
    self.locationManager = [[AMapLocationManager alloc] init];
    [self.locationManager setDesiredAccuracy:kCLLocationAccuracyHundredMeters];
    self.locationManager.locationTimeout =10;
    
    [self.locationManager requestLocationWithReGeocode:YES completionBlock:^(CLLocation *location, AMapLocationReGeocode *regeocode, NSError *error) {
        
        if (error)
        {
            NSLog(@"locError:{%ld - %@};", (long)error.code, error.localizedDescription);
            
            if (error.code == AMapLocationErrorLocateFailed)
            {
                return;
            }
        }

        ZDLog(@"%s---%d---location:%@",__func__,__LINE__,location);
        [[NSUserDefaults standardUserDefaults] setFloat:location.coordinate.latitude forKey:LOCATION_LAT];
        [[NSUserDefaults standardUserDefaults] setFloat:location.coordinate.longitude forKey:LOCATION_LONG];

        if (regeocode)
        {
            ZDLog(@"reGeocode:%@", regeocode);
        }
    }];


}

@end
